{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time seconds: 1.8961942195892334\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2000-01-21 20:00:00    0\n",
       "2000-01-21 21:00:00    0\n",
       "2000-01-21 22:00:00    0\n",
       "2000-01-21 23:00:00    0\n",
       "2000-01-22 00:00:00    0\n",
       "                      ..\n",
       "2000-02-11 11:00:00    0\n",
       "2000-02-11 12:00:00    0\n",
       "2000-02-11 13:00:00    0\n",
       "2000-02-11 14:00:00    1\n",
       "2000-02-11 15:00:00    1\n",
       "Freq: H, Length: 500, dtype: int32"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import arimafd as oa\n",
    "\n",
    "my_array = np.random.normal(size=1000) # init array\n",
    "my_array[-3] = 1000 # init anomaly\n",
    "ts = pd.DataFrame(my_array,\n",
    "                  index=pd.date_range(start='01-01-2000',\n",
    "                                      periods=1000,\n",
    "                                      freq='H'))\n",
    "\n",
    "my_arima = oa.Arima_anomaly_detection(ar_order=3)\n",
    "my_arima.fit(ts[:500])\n",
    "ts_anomaly = my_arima.predict(ts[500:])\n",
    "\n",
    "\n",
    "# or you can use for streaming:\n",
    "# bin_metric = []\n",
    "# for i in range(len(df)):\n",
    "#     bin_metric.append(my_arima.predict(df[i:i+1]))\n",
    "# bin_metric = pd.concat(bin_metric)\n",
    "# bin_metric\n",
    "\n",
    "# for evaluating results you can use https://tsad.readthedocs.io/en/latest/Evaluating.html \n",
    "ts_anomaly"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time seconds: 1.6653633117675781\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2000-01-01 03:00:00    0\n",
       "2000-01-01 04:00:00    0\n",
       "2000-01-01 05:00:00    0\n",
       "2000-01-01 06:00:00    0\n",
       "2000-01-01 07:00:00    0\n",
       "                      ..\n",
       "2000-02-11 11:00:00    0\n",
       "2000-02-11 12:00:00    0\n",
       "2000-02-11 13:00:00    0\n",
       "2000-02-11 14:00:00    1\n",
       "2000-02-11 15:00:00    1\n",
       "Freq: H, Length: 997, dtype: int32"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_array = np.random.normal(size=1000) # init array\n",
    "my_array[-3] = 1000 # init anomaly\n",
    "ts = pd.DataFrame(my_array,\n",
    "                  index=pd.date_range(start='01-01-2000',\n",
    "                                      periods=1000,\n",
    "                                      freq='H'))\n",
    "ad = oa.anomaly_detection(ts) #init anomaly detection algorithm\n",
    "ad.generate_tensor(ar_order=3) #it compute weights of ARIMA on history \n",
    "ts_anomaly = ad.proc_tensor() #processing of weights. \n",
    "# ad.ebeluate_nab() # function for evaluating results of algorithms\n",
    "ts_anomaly"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
